<!DOCTYPE html>
<html lang="en" xmlns:C="http://java.sun.com/jsp/jstl/core" xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>仓储宝 - 商品列表</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <style>
        .actions-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .search-form {
            display: flex;
            align-items: center;
        }

        .search-input {
            height: 30px; /* Adjust the height as needed */
            margin-right: 5px;
        }


    </style>
</head>

<body class="gray-bg">

<div class="container-fluid">

            <div class="ibox-title actions-container">
                <button id="return" type="button" class="btn btn-primary btn-sm">
                    <a href="/listProduct" style="color: white;">返回列表</a>
                </button>

                <form action="/toSelectProduct" class="search-form">
                    <div class="search-container">
                        <input type="text" name="search" placeholder="输入搜索关键词" class="search-input">
                        <button class="btn btn-primary" type="submit">搜索</button>
                    </div>
                </form>
            </div>
            <div class="table-responsive">
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>商品名字</th>
                        <th>数量</th>
                        <th>单位</th>
                        <th>品牌</th>
                        <th>仓库</th>
                        <th>产地</th>
                        <th>类型</th>
                        <th>介绍</th>
                        <th>进价/￥</th>
                        <th>售价/￥</th>
                        <th>上下架状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="productList:${productList}">
                        <td>[(${productList.product_id})]</td>
                        <td>[(${productList.product_name})]</td>
                        <td>[(${productList.product_num})]</td>
                        <td>[(${productList.unit_name})]</td>
                        <td>[(${productList.brand_name})]</td>
                        <td>[(${productList.store_name})]</td>
                        <td>[(${productList.place_name})]</td>
                        <td>[(${productList.type_name})]</td>
                        <td>[(${productList.introduce})]</td>
                        <td>[(${productList.in_price})]</td>
                        <td>[(${productList.sale_price})]</td>
                        <td>[(${productList.up_down_state})]</td>
                        <td>
                            <button>
                                <a th:href="@{/deleteProduct(product_id=${productList.product_id})}"
                                   onclick="deleteProduct('${productList.product_id}')">删除</a>
                            </button>
                            <button>
                                <a th:href="@{/toUpdateProduct(product_id=${productList.product_id})}">
                                    更新
                                </a>
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>

</div>
<script>
    function deleteProduct(product_id) {
        var flag = confirm("确定删除？");
        if (flag) {
            location.href = "deleteProduct?product_id=" + product_id;
        }
    }

    //搜索
    $(document).ready(function() {
        $('#searchButton').click(function() {
            var search = $('#searchInput').val().trim();

            if (search !== '') {
                $.post('/selectProduct', { search: search }, function(data) {
                    var highlightedData = highlightKeyword(data, search);
                    $('#listProduct').html(highlightedData);
                });
            } else {
                alert('请输入搜索关键词');
            }
        });

        显示关键词的函数
        function highlightKeyword(text, search) {
            var regex = new RegExp('(' + search + ')', 'gi');
            return text.replace(regex, '<span class="search-result">$1</span>');
        }
    });

</script>



<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.7"></script>



<!-- Peity -->
<script src="js/plugins/peity/jquery.peity.min.js"></script>

<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>


<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>

<!-- Peity -->
<script src="js/demo/peity-demo.js"></script>




<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<!--统计代码，可删除-->

</body>

</html>